﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utilities
{
    public class FileHelper
    {
        string path;
        FileStream stream;

        public FileHelper(string filePath)
        {
            path = filePath;
        }

        void OpenToRead()
        {
            stream = new FileStream(path, FileMode.Open, FileAccess.Read);
        }

        void OpenToWrite()
        {
            stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
        }

        void OpenToAppend()
        {
            stream = new FileStream(path, FileMode.Append, FileAccess.Write);
        }

        public void AppendLine(string data)
        {
            OpenToAppend();
            StreamWriter sw = new StreamWriter(stream);
            sw.WriteLine(data);
            sw.Close();
        }

        public void WriteLine(string data)
        {
            OpenToWrite();
            StreamWriter sw = new StreamWriter(stream);
            sw.WriteLine(data);
            sw.Close();
        }

        public string ReadAll()
        {
            OpenToRead();
            StreamReader sr = new StreamReader(stream);
            string data = sr.ReadToEnd();
            sr.Close();
            return data;
        }
    }
}
